package com.ljz.controller.pc;

import com.ljz.common.core.controller.MyBaseController;
import com.ljz.common.dao.bean.PageResult;
import com.ljz.common.utils.ReturnResult;
import com.ljz.entity.Spu;
import com.ljz.query.SpuQuery;
import com.ljz.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/pc")
@Api(tags = "商品管理")
public class PcSpuController extends MyBaseController {

    @Autowired
    SpuService spuService;

    @ApiOperation("添加商品")
    @PostMapping("/product")
    public ReturnResult save(@RequestBody Spu spu) {

        int res = spuService.saveEntity(spu);
        return saveResult(res);
    }

    @ApiOperation("查询商品列表")
    @PostMapping("/product/list")
    public ReturnResult findAll(@RequestBody SpuQuery spuQuery) {

        PageResult<Map> spuPageResult = spuService.querySpuByPage(spuQuery);
        return success("商品列表",spuPageResult);
    }

    @ApiOperation("根据id查询商品信息")
    @GetMapping("/product")
    public ReturnResult findById(Long id) {

        Map map = spuService.querySpuById(id);

        return success("商品信息",map);

    }

}
